home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 335_02 / as7000.y < prev    next >
Text File  |  1990-12-02  |  38KB  |  1,660 lines

  1. %{
  2.  
  3. /*
  4. HEADER:     ;
  5. TITLE:         Frankenstein Cross Assemblers;
  6. VERSION:     2.0;
  7. DESCRIPTION: "    Reconfigurable Cross-assembler producing Intel (TM)
  8.         Hex format object records.  ";
  9. KEYWORDS:     cross-assemblers, 1805, 2650, 6301, 6502, 6805, 6809, 
  10.         6811, tms7000, 8048, 8051, 8096, z8, z80;
  11. SYSTEM:     UNIX, MS-Dos ;
  12. FILENAME:     as7000.y;
  13. WARNINGS:     "The language defined in this file does
  14.         not follow the standard Texas Instruments syntax.
  15.  
  16.         This software is in the public domain.  
  17.         Any prior copyright claims are relinquished.  
  18.  
  19.         This software is distributed with no warranty whatever.  
  20.         The author takes no responsibility for the consequences 
  21.         of its use.
  22.  
  23.         Yacc (or Bison) required to compile."  ;
  24. SEE-ALSO:     as7000.doc,frasmain.c;    
  25. AUTHORS:     Mark Zenier;
  26. COMPILERS:     Microport Sys V/AT, ATT Yacc, Turbo C V1.5, Bison (CUG disk 285)
  27.         (previous versions Xenix, Unisoft 68000 Version 7, Sun 3);
  28. */
  29. /* TMS7000 instruction generation file */
  30. /* November 17, 1990 */
  31.  
  32. /*
  33.     description    frame work parser description for framework cross
  34.             assemblers
  35.     history        February 2, 1988
  36.             September 11, 1990 - merge table definition
  37.             September 12, 1990 - short file names
  38.             September 14, 1990 - short variable names
  39.             September 17, 1990 - use yylex as external
  40. */
  41. #include <stdio.h>
  42. #include "frasmdat.h"
  43. #include "fragcon.h"
  44.  
  45. #define yylex lexintercept
  46.  
  47.  /*    0000.0000.0000.00xx */
  48. #define    DSTMASK        0x3
  49. #define    DSTA        0x1
  50. #define    DSTB        0x2
  51.  /*     0000.0000.0000.xx00 */
  52. #define    SRCMASK        0xc
  53. #define    SRCA        0x4
  54. #define    SRCB        0x8
  55. #define ST_INH 0x1
  56. #define ST_EXPR 0x2
  57. #define ST_EXPR2 0x4
  58. #define ST_EXPR3 0x8
  59. #define ST_IEXPR2 0x10
  60. #define ST_IEXPR3 0x20
  61. #define ST_INDEX 0x40
  62. #define ST_IMMIND 0x80
  63. #define ST_RINDIR 0x100
  64. #define ST_STATUS 0x200
  65.     
  66.     static int operselbits;
  67.     static char    genbdef[] = "[1=];";
  68.     static char    genwdef[] = "[1=]x"; /* x for normal, y for byte rev */
  69.     char ignosyn[] = "[Xinvalid syntax for instruction";
  70.     char ignosel[] = "[Xinvalid operands/illegal instruction for cpu";
  71.  
  72.     long    labelloc;
  73.     static int satsub;
  74.     int    ifstkpt = 0;
  75.     int    fraifskip = FALSE;
  76.  
  77.     struct symel * endsymbol = SYMNULL;
  78.  
  79. %}
  80. %union {
  81.     int    intv;
  82.     long     longv;
  83.     char    *strng;
  84.     struct symel *symb;
  85. }
  86.  
  87. %token STATUS
  88. %token <intv> REG
  89. %token <intv> KOC_BDEF
  90. %token <intv> KOC_ELSE
  91. %token <intv> KOC_END
  92. %token <intv> KOC_ENDI
  93. %token <intv> KOC_EQU
  94. %token <intv> KOC_IF
  95. %token <intv> KOC_INCLUDE
  96. %token <intv> KOC_ORG
  97. %token <intv> KOC_RESM
  98. %token <intv> KOC_SDEF
  99. %token <intv> KOC_SET
  100. %token <intv> KOC_WDEF
  101. %token <intv> KOC_CHSET
  102. %token <intv> KOC_CHDEF
  103. %token <intv> KOC_CHUSE
  104. %token <intv> KOC_opcode
  105.  
  106. %token <longv> CONSTANT
  107. %token EOL
  108. %token KEOP_AND
  109. %token KEOP_DEFINED
  110. %token KEOP_EQ
  111. %token KEOP_GE
  112. %token KEOP_GT
  113. %token KEOP_HIGH
  114. %token KEOP_LE
  115. %token KEOP_LOW
  116. %token KEOP_LT
  117. %token KEOP_MOD
  118. %token KEOP_MUN
  119. %token KEOP_NE
  120. %token KEOP_NOT
  121. %token KEOP_OR
  122. %token KEOP_SHL
  123. %token KEOP_SHR
  124. %token KEOP_XOR
  125. %token KEOP_locctr
  126. %token <symb> LABEL
  127. %token <strng> STRING
  128. %token <symb> SYMBOL
  129.  
  130. %token KTK_invalid
  131.  
  132. %right    KEOP_HIGH KEOP_LOW
  133. %left    KEOP_OR KEOP_XOR
  134. %left    KEOP_AND
  135. %right    KEOP_NOT
  136. %nonassoc    KEOP_GT KEOP_GE KEOP_LE KEOP_LT KEOP_NE KEOP_EQ
  137. %left    '+' '-'
  138. %left    '*' '/' KEOP_MOD KEOP_SHL KEOP_SHR
  139. %right    KEOP_MUN
  140.  
  141.  
  142. %type <intv> expr exprlist stringlist
  143.  
  144. %start file
  145.  
  146. %%
  147.  
  148. file    :    file allline
  149.     |    allline
  150.     ;
  151.  
  152. allline    :     line EOL
  153.             {
  154.                 clrexpr();
  155.             }
  156.     |    EOL
  157.     |    error EOL
  158.             {
  159.                 clrexpr();
  160.                 yyerrok;
  161.             }
  162.     ;
  163.  
  164. line    :    LABEL KOC_END 
  165.             {
  166.                 endsymbol = $1;
  167.                 nextreadact = Nra_end;
  168.             }
  169.     |          KOC_END 
  170.             {
  171.                 nextreadact = Nra_end;
  172.             }
  173.     |    KOC_INCLUDE STRING
  174.             {
  175.         if(nextfstk >= FILESTKDPTH)
  176.         {
  177.             fraerror("include file nesting limit exceeded");
  178.         }
  179.         else
  180.         {
  181.             infilestk[nextfstk].fnm = savestring($2,strlen($2));
  182.             if( (infilestk[nextfstk].fpt = fopen($2,"r"))
  183.                 ==(FILE *)NULL )
  184.             {
  185.                 fraerror("cannot open include file");
  186.             }
  187.             else
  188.             {
  189.                 nextreadact = Nra_new;
  190.             }
  191.         }
  192.             }
  193.     |    LABEL KOC_EQU expr 
  194.             {
  195.                 if($1 -> seg == SSG_UNDEF)
  196.                 {
  197.                     pevalexpr(0, $3);
  198.                     if(evalr[0].seg == SSG_ABS)
  199.                     {
  200.                         $1 -> seg = SSG_EQU;
  201.                         $1 -> value = evalr[0].value;
  202.                         prtequvalue("C: 0x%lx\n",
  203.                             evalr[0].value);
  204.                     }
  205.                     else
  206.                     {
  207.                         fraerror(
  208.                     "noncomputable expression for EQU");
  209.                     }
  210.                 }
  211.                 else
  212.                 {
  213.                     fraerror(
  214.                 "cannot change symbol value with EQU");
  215.                 }
  216.             }
  217.     |    LABEL KOC_SET expr 
  218.             {
  219.                 if($1 -> seg == SSG_UNDEF
  220.                    || $1 -> seg == SSG_SET)
  221.                 {
  222.                     pevalexpr(0, $3);
  223.                     if(evalr[0].seg == SSG_ABS)
  224.                     {
  225.                         $1 -> seg = SSG_SET;
  226.                         $1 -> value = evalr[0].value;
  227.                         prtequvalue("C: 0x%lx\n",
  228.                             evalr[0].value);
  229.                     }
  230.                     else
  231.                     {
  232.                         fraerror(
  233.                     "noncomputable expression for SET");
  234.                     }
  235.                 }
  236.                 else
  237.                 {
  238.                     fraerror(
  239.                 "cannot change symbol value with SET");
  240.                 }
  241.             }
  242.     |    KOC_IF expr 
  243.             {
  244.         if((++ifstkpt) < IFSTKDEPTH)
  245.         {
  246.             pevalexpr(0, $2);
  247.             if(evalr[0].seg == SSG_ABS)
  248.             {
  249.                 if(evalr[0].value != 0)
  250.                 {
  251.                     elseifstk[ifstkpt] = If_Skip;
  252.                     endifstk[ifstkpt] = If_Active;
  253.                 }
  254.                 else
  255.                 {
  256.                     fraifskip = TRUE;
  257.                     elseifstk[ifstkpt] = If_Active;
  258.                     endifstk[ifstkpt] = If_Active;
  259.                 }
  260.             }
  261.             else
  262.             {
  263.                 fraifskip = TRUE;
  264.                 elseifstk[ifstkpt] = If_Active;
  265.                 endifstk[ifstkpt] = If_Active;
  266.             }
  267.         }
  268.         else
  269.         {
  270.             fraerror("IF stack overflow");
  271.         }
  272.             }
  273.                         
  274.     |    KOC_IF 
  275.             {
  276.         if(fraifskip) 
  277.         {
  278.             if((++ifstkpt) < IFSTKDEPTH)
  279.             {
  280.                     elseifstk[ifstkpt] = If_Skip;
  281.                     endifstk[ifstkpt] = If_Skip;
  282.             }
  283.             else
  284.             {
  285.                 fraerror("IF stack overflow");
  286.             }
  287.         }
  288.         else
  289.         {
  290.             yyerror("syntax error");
  291.             YYERROR;
  292.         }
  293.                 }
  294.                         
  295.     |    KOC_ELSE 
  296.             {
  297.                 switch(elseifstk[ifstkpt])
  298.                 {
  299.                 case If_Active:
  300.                     fraifskip = FALSE;
  301.                     break;
  302.                 
  303.                 case If_Skip:
  304.                     fraifskip = TRUE;
  305.                     break;
  306.                 
  307.                 case If_Err:
  308.                     fraerror("ELSE with no matching if");
  309.                     break;
  310.                 }
  311.             }
  312.  
  313.     |    KOC_ENDI 
  314.             {
  315.                 switch(endifstk[ifstkpt])
  316.                 {
  317.                 case If_Active:
  318.                     fraifskip = FALSE;
  319.                     ifstkpt--;
  320.                     break;
  321.                 
  322.                 case If_Skip:
  323.                     fraifskip = TRUE;
  324.                     ifstkpt--;
  325.                     break;
  326.                 
  327.                 case If_Err:
  328.                     fraerror("ENDI with no matching if");
  329.                     break;
  330.                 }
  331.             }
  332.     |    LABEL KOC_ORG expr 
  333.             {
  334.                 pevalexpr(0, $3);
  335.                 if(evalr[0].seg == SSG_ABS)
  336.                 {
  337.                     locctr = labelloc = evalr[0].value;
  338.                     if($1 -> seg == SSG_UNDEF)
  339.                     {
  340.                         $1 -> seg = SSG_ABS;
  341.                         $1 -> value = labelloc;
  342.                     }
  343.                     else
  344.                         fraerror(
  345.                         "multiple definition of label");
  346.                     prtequvalue("C: 0x%lx\n",
  347.                         evalr[0].value);
  348.                 }
  349.                 else
  350.                 {
  351.                     fraerror(
  352.                      "noncomputable expression for ORG");
  353.                 }
  354.             }
  355.     |          KOC_ORG expr 
  356.             {
  357.                 pevalexpr(0, $2);
  358.                 if(evalr[0].seg == SSG_ABS)
  359.                 {
  360.                     locctr = labelloc = evalr[0].value;
  361.                     prtequvalue("C: 0x%lx\n",
  362.                         evalr[0].value);
  363.                 }
  364.                 else
  365.                 {
  366.                     fraerror(
  367.                      "noncomputable expression for ORG");
  368.                 }
  369.             }
  370.     |    LABEL KOC_CHSET
  371.             {
  372.                 if($1 -> seg == SSG_UNDEF)
  373.                 {
  374.                     $1 -> seg = SSG_EQU;
  375.                     if( ($1->value = chtcreate()) <= 0)
  376.                     {
  377.         fraerror( "cannot create character translation table");
  378.                     }
  379.                     prtequvalue("C: 0x%lx\n", $1 -> value);
  380.                 }
  381.                 else
  382.                 {
  383.             fraerror( "multiple definition of label");
  384.                 }
  385.             }
  386.     |        KOC_CHUSE
  387.             {
  388.                 chtcpoint = (int *) NULL;
  389.                 prtequvalue("C: 0x%lx\n", 0L);
  390.             }
  391.     |        KOC_CHUSE expr
  392.             {
  393.                 pevalexpr(0, $2);
  394.                 if( evalr[0].seg == SSG_ABS)
  395.                 {
  396.                     if( evalr[0].value == 0)
  397.                     {
  398.                         chtcpoint = (int *)NULL;
  399.                         prtequvalue("C: 0x%lx\n", 0L);
  400.                     }
  401.                     else if(evalr[0].value < chtnxalph)
  402.                     {
  403.                 chtcpoint = chtatab[evalr[0].value];
  404.                 prtequvalue("C: 0x%lx\n", evalr[0].value);
  405.                     }
  406.                     else
  407.                     {
  408.             fraerror("nonexistent character translation table");
  409.                     }
  410.                 }
  411.                 else
  412.                 {
  413.                     fraerror("noncomputable expression");
  414.                 }
  415.             }
  416.     |        KOC_CHDEF STRING ',' exprlist